/*************************************************************************
    > File Name: buffering.c
    > Author: Xing.Dai
    > Mail: Xing.Dai@aliyun.com 
    > Created Time: 2017-04-01 23:49
 ************************************************************************/

#include "apue.h"
#include <sys/time.h>

int main(int argc, char **argv)
{
	int glo = 5;
	pid_t pid;
	struct timeval tsf;
	
	gettimeofday(&tsf, NULL);
	printf("[%u]before fork\n", (unsigned int)tsf.tv_usec);

	if((pid = fork()) < 0){
		err_sys("fork error");
	} else {
		if(pid == 0){
			// Child process.
			glo++;
		} else {
			sleep(4);
		}
	}

	gettimeofday(&tsf, NULL);
	printf("[%u]pid = %d glo =  %d.\n", (unsigned int)tsf.tv_usec, getpid(), glo);

	exit(0);
}
